#define _CRT_SECURE_NO_WARNINGS 1
#include<stdlib.h>

int* sortArrayByParityII(int* nums, int numsSize, int* returnSize) {
    int mid = numsSize / 2;
    int* tmp1 = (int*)malloc(sizeof(int) * mid);
    int* tmp2 = (int*)malloc(sizeof(int) * mid);
    int* ret = (int*)malloc(sizeof(int) * numsSize);
    *returnSize = numsSize;
    int i, j = 0, k = 0;
    for (i = 0; i < numsSize; i++)
    {
        if (nums[i] % 2 == 0)
        {
            tmp1[j++] = nums[i];
        }
        else
        {
            tmp2[k++] = nums[i];
        }
    }
    j = 0;
    k = 0;
    for (i = 0; i < numsSize; i += 2)
    {
        ret[i] = tmp1[j++];
    }
    for (i = 1; i < numsSize; i += 2)
    {
        ret[i] = tmp2[k++];
    }
    return ret;
}